ConfigApi

object ConfigApi

API for management of config files. If writing in Java, consider using ConfigApiJava where possible.

Configs can de/serialized from File, string, or raw TomlElement. File read is performed with validation and correction.

Author

fzzyhmstrs

Since

0.1.0

Functions

Link copied to clipboard
fun <T : Any> deserializeConfig(config: T, string: String, errorBuilder: MutableList<String>, flags: Byte = 1): ValidationResult<ConfigContext<T>>

Deserializes a config from a string.

Link copied to clipboard
fun <T : Any> deserializeFromToml(config: T, toml: TomlElement, errorBuilder: MutableList<String>, flags: Byte = 1): ValidationResult<ConfigContext<T>>

Deserializes a config class from a TomlElement

Link copied to clipboard

Provides an instance of the EventApi for registering to config events

Link copied to clipboard
Link copied to clipboard
fun makeDir(folder: String, subfolder: String): Pair<File, Boolean>

Creates a config directory keyed off the standard Fabric Config Directory

Link copied to clipboard

Provides an instance of the NetworkApi for usage of the built-in cross-loader networking API

Link copied to clipboard
fun openScreen(scope: String)

Opens a config GUI. Does nothing on the server (But is not marked with @Environment, allowing for safe inclusion anywhere in code)

Link copied to clipboard

Provides an instance of the PlatformApi for usage of the built-in cross-loader utilities

Link copied to clipboard
fun <T : Config> readOrCreateAndValidate(configClass: () -> T): T

overload of readOrCreateAndValidate that automatically applies the name, folder, and subfolder from the config itself. Automatically adds ".toml" to the name for reading and writing.

fun <T : Config> readOrCreateAndValidate(name: String, folder: String = "", subfolder: String = "", configClass: Supplier<T>): T
fun <T : Config> readOrCreateAndValidate(name: String, folder: String = "", subfolder: String = "", configClass: () -> T): T

Reads a config from File or Creates a new config class; writes out any corrections, updates, or new content to File. Automatically adds ".toml" to the name for reading and writing.

Link copied to clipboard
fun <T : Config> registerAndLoadConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T
fun <T : Config> registerAndLoadConfig(configClass: () -> T, registerType: RegisterType = RegisterType.BOTH): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Link copied to clipboard
fun <T : Config> registerConfig(config: T, configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T
fun <T : Config> registerConfig(config: T, configClass: () -> T, registerType: RegisterType = RegisterType.BOTH): T

Registers a Config to registries. Does NOT load or validate it from file. Use this if you have custom initialization to perform, otherwise use registerAndLoadConfig for full initialization functionality.

Link copied to clipboard
@ApiStatus.Experimental
fun result(): ResultApi

Provides an instance of the ResultApi for creation of ResultProvider to indirectly refer to configs via scope strings

Link copied to clipboard
fun <T : Config> save(configClass: T)

Overload of saveManual that automatically fills in name, folder, and subfolder from the config itself.

Link copied to clipboard
fun <T : Config> saveManual(name: String, folder: String = "", subfolder: String = "", configClass: T)

Saves a config to file without reading or updating.

Link copied to clipboard
fun <T : Any> serializeConfig(config: T, errorBuilder: MutableList<String>, flags: Byte = 1): String

Serializes a config class to a string.

Link copied to clipboard
fun <T : Any> serializeToToml(config: T, errorBuilder: MutableList<String>, flags: Byte = 1): TomlElement

Serialize a config class to a TomlElement